package com.lyn.scan.mvvm.presenter

import java.util.concurrent.*


/**
 * @author Lyn
 * @date 2022/7/13
 * @desc
 */
class ThreadPoolManager(threadPool: ThreadPoolExecutor?) {

    val threadPool: ThreadPoolExecutor

    init {
        this.threadPool = threadPool!!
    }


    companion object {
        private const val CORE_POOL_SIZE = 1
        private const val MAX_POOL_SIZE = 5;
        var instance: ThreadPoolManager? = null

        @Synchronized
        fun get(): ThreadPoolManager {
            instance?.let { return it }
            return ThreadPoolManager(
                ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, 3, TimeUnit.SECONDS, LinkedBlockingDeque())
            ).apply { instance = this }
        }
    }


}